//
//  ZWRetweetStatusView.swift
//  ZWWeibo
//
//  Created by flyiron on 16/4/21.
//  Copyright © 2016年 flyiron. All rights reserved.
//

import UIKit
import SnapKit



class ZWRetweetStatusView: UIView {
    var bottomCons:Constraint?
    
    var statusViewModel:ZWStatusesViewModel? {
        didSet{
           retweetStatusLabel.text = statusViewModel?.retweetText
            bottomCons?.uninstall()
            if let pic_urls = statusViewModel?.status?.retweeted_status?.pic_urls where pic_urls.count > 0{
                
                retweetImageView.hidden = false
//                print(pic_urls.count)
                retweetImageView.snp_updateConstraints(closure: { (make) -> Void in
                    make.size.equalTo(statusViewModel?.reweetPictureViewSize ?? CGSizeZero)
                    
                })
                retweetImageView.pic_urls = pic_urls
                
                snp_makeConstraints(closure: { (make) -> Void in
                    bottomCons = make.bottom.equalTo(retweetImageView.snp_bottom).offset(ZWStatusCellMargin).constraint
                })

            }else{
                retweetImageView.hidden = true
//                retweetImageView.snp_updateConstraints(closure: { (make) -> Void in
//                    make.size.equalTo(CGSizeZero)
//                })               
                snp_makeConstraints(closure: { (make) -> Void in
                    bottomCons = make.bottom.equalTo(retweetStatusLabel).offset(ZWStatusCellMargin).constraint

                })
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
//        backgroundColor = UIColor.blueColor()
        backgroundColor = UIColor(white: 245/255, alpha: 1)
        addSubview(retweetStatusLabel)
        addSubview(retweetImageView)
        
        retweetStatusLabel.snp_makeConstraints { (make) -> Void in
            make.top.leading.equalTo(self).offset(ZWStatusCellMargin)
        }
        retweetImageView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetStatusLabel.snp_bottom).offset(ZWStatusCellMargin)
            make.leading.equalTo(retweetStatusLabel)
            
//            make.size.equalTo(CGSize(width: 100, height: 100))
        }
        snp_updateConstraints { (make) -> Void in
          bottomCons = make.bottom.equalTo(retweetImageView).offset(ZWStatusCellMargin).constraint
        }
    }
    
    private lazy var retweetStatusLabel:UILabel = {
    let label = UILabel(textColor: UIColor.darkGrayColor(), fontSize: ZWStatusCellContentFontSize, preferredMaxLayoutWidth: SCREENW - 2 * ZWStatusCellMargin)
        return label
    }()
    
    private lazy var retweetImageView = ZWStatusPictureView(frame: CGRectZero, collectionViewLayout: UICollectionViewFlowLayout())
}
